/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.financial.entity.ttpaymentorder;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.modules.base.entity.customer.Customer;
import com.jeesite.modules.base.entity.supplier.Supplier;
import com.jeesite.modules.logistics.entity.overseaswarehouse.OverseasWarehouse;
import com.jeesite.modules.order.entity.serviceorder.ServiceOrder;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * TT付款单Entity
 * @author Kilo
 * @version 2021-03-10
 */
@Table(name="t_tt_payment_order", alias="a", columns={
		@Column(name="tt_payment_order_id", attrName="ttPaymentOrderId", label="TT付款单ID", isPK=true),
		@Column(name="payment_order_code", attrName="paymentOrderCode", label="编号"),
		@Column(name="service_order_id", attrName="serviceOrderId", label="服务订单"),
		@Column(name="customer_id", attrName="customer.customerId", label="客户"),
		@Column(name="investor_id", attrName="investorId", label="资方"),
		@Column(name="foreign_businessmen_id", attrName="foreignBusinessmenId", label="外商"),
		@Column(name="foreign_businessmen_bank", attrName="foreignBusinessmenBank", label="外商银行账号"),
		@Column(name="overseas_warehouse_code", attrName="overseasWarehouseCode", label="海外仓单据号"),
		@Column(name="foreign_businessmen_address", attrName="foreignBusinessmenAddress", label="外商地址"),
		@Column(name="bank", attrName="bank", label="银行名称"),
		@Column(name="bank_address", attrName="bankAddress", label="银行地址"),
		@Column(name="swift_code", attrName="swiftCode", label="swift码"),
		@Column(name="remarks", attrName="remarks", label="备注信息", isQuery=false),
		@Column(name="margin_ratio", attrName="marginRatio", label="保证金比例"),
		@Column(name="margin_received", attrName="marginReceived", label="已收保证金"),
		@Column(name="currency", attrName="currency", label="币种"),
		@Column(name="purchase_amount", attrName="purchaseAmount", label="购汇金额"),
		@Column(name="purchase_exchange_rate", attrName="purchaseExchangeRate", label="购汇汇率"),
		@Column(name="rmb_equivalent", attrName="rmbEquivalent", label="等值人民币价额"),
		@Column(name="telegram_fee", attrName="telegramFee", label="电报费", comment="电报费（RMB）"),
		@Column(name="handling_fee", attrName="handlingFee", label="手续费", comment="手续费（RMB）"),
		@Column(name="total", attrName="total", label="合计", comment="合计（RMB）"),
		@Column(name="payment_date", attrName="paymentDate", label="付汇日期"),
		@Column(name="transaction_memo", attrName="transactionMemo", label="交易附言"),
		@Column(name="create_by", attrName="createBy", label="创建者", isUpdate=false),
		@Column(name="create_date", attrName="createDate", label="创建时间", isUpdate=false),
		@Column(name="update_by", attrName="updateBy", label="更新者", isQuery=false),
		@Column(name="update_date", attrName="updateDate", label="更新时间", isQuery=false),
		@Column(name="ar_id", attrName="arId", label="应收单ID"),
		@Column(name="ap_id", attrName="apId", label="应付单ID"),
	}, joinTable={
		@JoinTable(type=Type.LEFT_JOIN, entity= Customer.class, attrName="customer", alias="c",
				on="c.customer_id = a.customer_id", columns={
				@Column(name="customer_id", label="客户编码", isPK=true),
				@Column(name="customer_name", label="客户名称", isQuery=false),
		}),
		@JoinTable(type=Type.LEFT_JOIN, entity= Supplier.class, attrName="investor", alias="e",
				on="e.supplier_id = a.investor_id", columns={
				@Column(name="supplier_id", label="国内资方编码", isPK=true),
				@Column(name="supplier_name", label="国内资方名称", isQuery=false),
		}),
		@JoinTable(type=Type.LEFT_JOIN, entity= Supplier.class, attrName="foreignBusinessmen", alias="f",
				on="f.supplier_id = a.foreign_businessmen_id", columns={
				@Column(name="supplier_id", label="外商编码", isPK=true),
				@Column(name="supplier_name", label="外商名称", isQuery=false),
		}),
		@JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = ServiceOrder.class, attrName = "serviceOrder", alias = "s",
				on = "s.service_order_id = a.service_order_id",
				columns = {
				@Column(name = "service_order_id", label = "服务订单ID", isPK = true),
				@Column(name = "service_order_code", label = "服务订单编号"),
		}),
		@JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = OverseasWarehouse.class, attrName = "overseasWarehouse", alias = "o",
				on = "o.overseas_warehouse_id = a.overseas_warehouse_code",
				columns = {
				@Column(name = "overseas_warehouse_id", label = "海外仓ID", isPK = true),
				@Column(name = "overseas_warehouse_code", label = "海外仓编号"),
		}),
	}, orderBy="a.update_date DESC"
)
public class TtPaymentOrder extends DataEntity<TtPaymentOrder> {
	
	private static final long serialVersionUID = 1L;
	private String ttPaymentOrderId;		// TT付款单ID
	private String paymentOrderCode;		// 编号
	private String serviceOrderId;		// 服务订单
	private String customerId;		// 客户
	private String investorId;		// 资方
	private String foreignBusinessmenId;		// 外商
	private String foreignBusinessmenBank;		// 外商银行账号
	private String overseasWarehouseCode;		// 海外仓单据号
	private String foreignBusinessmenAddress;		// 外商地址
	private String bank;		// 银行名称
	private String bankAddress;		// 银行地址
	private String swiftCode;		// swift码
	private String marginRatio;		// 保证金比例
	private Double marginReceived;		// 已收保证金
	private String currency;		// 币种
	private Double purchaseAmount;		// 购汇金额
	private String purchaseExchangeRate;		// 购汇汇率
	private Double rmbEquivalent;		// 等值人民币价额
	private Double telegramFee;		// 电报费（RMB）
	private Double handlingFee;		// 手续费（RMB）
	private Double total;		// 合计（RMB）
	private Date paymentDate;		// 付汇日期
	private String transactionMemo;		// 交易附言
	private List<TtPaymentOrderDetail> ttPaymentOrderDetailList = ListUtils.newArrayList();		// 子表列表
	private Customer customer;
	private Supplier investor;
	private Supplier foreignBusinessmen;
	private ServiceOrder serviceOrder;        // 服务订单
	private OverseasWarehouse overseasWarehouse; // 海外仓
	private String arId;
	private String apId;
	private TtPaymentOrderDetail ttPaymentOrderDetail;

	public TtPaymentOrderDetail getTtPaymentOrderDetail() {
		return ttPaymentOrderDetail;
	}

	public void setTtPaymentOrderDetail(TtPaymentOrderDetail ttPaymentOrderDetail) {
		this.ttPaymentOrderDetail = ttPaymentOrderDetail;
	}

	public String getArId() {
		return arId;
	}

	public void setArId(String arId) {
		this.arId = arId;
	}

	public String getApId() {
		return apId;
	}

	public void setApId(String apId) {
		this.apId = apId;
	}

	public ServiceOrder getServiceOrder() {
		return serviceOrder;
	}

	public void setServiceOrder(ServiceOrder serviceOrder) {
		this.serviceOrder = serviceOrder;
	}

	public OverseasWarehouse getOverseasWarehouse() {
		return overseasWarehouse;
	}

	public void setOverseasWarehouse(OverseasWarehouse overseasWarehouse) {
		this.overseasWarehouse = overseasWarehouse;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Supplier getInvestor() {
		return investor;
	}

	public void setInvestor(Supplier investor) {
		this.investor = investor;
	}

	public Supplier getForeignBusinessmen() {
		return foreignBusinessmen;
	}

	public void setForeignBusinessmen(Supplier foreignBusinessmen) {
		this.foreignBusinessmen = foreignBusinessmen;
	}

	public TtPaymentOrder() {
		this(null);
	}

	public TtPaymentOrder(String id){
		super(id);
	}
	
	public String getTtPaymentOrderId() {
		return ttPaymentOrderId;
	}

	public void setTtPaymentOrderId(String ttPaymentOrderId) {
		this.ttPaymentOrderId = ttPaymentOrderId;
	}
	
	@Length(min=0, max=100, message="编号长度不能超过 100 个字符")
	public String getPaymentOrderCode() {
		return paymentOrderCode;
	}

	public void setPaymentOrderCode(String paymentOrderCode) {
		this.paymentOrderCode = paymentOrderCode;
	}
	
	@Length(min=0, max=64, message="服务订单长度不能超过 64 个字符")
	public String getServiceOrderId() {
		return serviceOrderId;
	}

	public void setServiceOrderId(String serviceOrderId) {
		this.serviceOrderId = serviceOrderId;
	}
	
	@Length(min=0, max=64, message="客户长度不能超过 64 个字符")
	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}
	
	@Length(min=0, max=64, message="资方长度不能超过 64 个字符")
	public String getInvestorId() {
		return investorId;
	}

	public void setInvestorId(String investorId) {
		this.investorId = investorId;
	}
	
	@Length(min=0, max=64, message="外商长度不能超过 64 个字符")
	public String getForeignBusinessmenId() {
		return foreignBusinessmenId;
	}

	public void setForeignBusinessmenId(String foreignBusinessmenId) {
		this.foreignBusinessmenId = foreignBusinessmenId;
	}
	
	@NotBlank(message="外商银行账号不能为空")
	@Length(min=0, max=100, message="外商银行账号长度不能超过 100 个字符")
	public String getForeignBusinessmenBank() {
		return foreignBusinessmenBank;
	}

	public void setForeignBusinessmenBank(String foreignBusinessmenBank) {
		this.foreignBusinessmenBank = foreignBusinessmenBank;
	}
	
	@Length(min=0, max=100, message="海外仓单据号长度不能超过 100 个字符")
	public String getOverseasWarehouseCode() {
		return overseasWarehouseCode;
	}

	public void setOverseasWarehouseCode(String overseasWarehouseCode) {
		this.overseasWarehouseCode = overseasWarehouseCode;
	}
	
	@Length(min=0, max=100, message="外商地址长度不能超过 100 个字符")
	public String getForeignBusinessmenAddress() {
		return foreignBusinessmenAddress;
	}

	public void setForeignBusinessmenAddress(String foreignBusinessmenAddress) {
		this.foreignBusinessmenAddress = foreignBusinessmenAddress;
	}
	
	@Length(min=0, max=100, message="银行名称长度不能超过 100 个字符")
	public String getBank() {
		return bank;
	}

	public void setBank(String bank) {
		this.bank = bank;
	}
	
	@Length(min=0, max=200, message="银行地址长度不能超过 200 个字符")
	public String getBankAddress() {
		return bankAddress;
	}

	public void setBankAddress(String bankAddress) {
		this.bankAddress = bankAddress;
	}
	
	@Length(min=0, max=200, message="swift码长度不能超过 200 个字符")
	public String getSwiftCode() {
		return swiftCode;
	}

	public void setSwiftCode(String swiftCode) {
		this.swiftCode = swiftCode;
	}
	
	@Length(min=0, max=10, message="保证金比例长度不能超过 10 个字符")
	public String getMarginRatio() {
		return marginRatio;
	}

	public void setMarginRatio(String marginRatio) {
		this.marginRatio = marginRatio;
	}
	
	public Double getMarginReceived() {
		return marginReceived;
	}

	public void setMarginReceived(Double marginReceived) {
		this.marginReceived = marginReceived;
	}
	
	@Length(min=0, max=2, message="币种长度不能超过 2 个字符")
	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}
	
	@NotNull(message="购汇金额不能为空")
	public Double getPurchaseAmount() {
		return purchaseAmount;
	}

	public void setPurchaseAmount(Double purchaseAmount) {
		this.purchaseAmount = purchaseAmount;
	}
	
	@Length(min=0, max=10, message="购汇汇率长度不能超过 10 个字符")
	public String getPurchaseExchangeRate() {
		return purchaseExchangeRate;
	}

	public void setPurchaseExchangeRate(String purchaseExchangeRate) {
		this.purchaseExchangeRate = purchaseExchangeRate;
	}
	
	public Double getRmbEquivalent() {
		return rmbEquivalent;
	}

	public void setRmbEquivalent(Double rmbEquivalent) {
		this.rmbEquivalent = rmbEquivalent;
	}
	
	public Double getTelegramFee() {
		return telegramFee;
	}

	public void setTelegramFee(Double telegramFee) {
		this.telegramFee = telegramFee;
	}
	
	public Double getHandlingFee() {
		return handlingFee;
	}

	public void setHandlingFee(Double handlingFee) {
		this.handlingFee = handlingFee;
	}
	
	public Double getTotal() {
		return total;
	}

	public void setTotal(Double total) {
		this.total = total;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getPaymentDate() {
		return paymentDate;
	}

	public void setPaymentDate(Date paymentDate) {
		this.paymentDate = paymentDate;
	}
	
	@Length(min=0, max=255, message="交易附言长度不能超过 255 个字符")
	public String getTransactionMemo() {
		return transactionMemo;
	}

	public void setTransactionMemo(String transactionMemo) {
		this.transactionMemo = transactionMemo;
	}
	
	public Date getPaymentDate_gte() {
		return sqlMap.getWhere().getValue("payment_date", QueryType.GTE);
	}

	public void setPaymentDate_gte(Date paymentDate) {
		sqlMap.getWhere().and("payment_date", QueryType.GTE, paymentDate);
	}
	
	public Date getPaymentDate_lte() {
		return sqlMap.getWhere().getValue("payment_date", QueryType.LTE);
	}

	public void setPaymentDate_lte(Date paymentDate) {
		sqlMap.getWhere().and("payment_date", QueryType.LTE, paymentDate);
	}
	
	public List<TtPaymentOrderDetail> getTtPaymentOrderDetailList() {
		return ttPaymentOrderDetailList;
	}

	public void setTtPaymentOrderDetailList(List<TtPaymentOrderDetail> ttPaymentOrderDetailList) {
		this.ttPaymentOrderDetailList = ttPaymentOrderDetailList;
	}
	
}